home *** CD-ROM | disk | FTP | other *** search
- /*
- * Emstest.c -- EMS Table Routines Test Pgm
- */
- #include "stddefs.h"
- #include "yaklist.h"
- #include "yakems.h"
- #include <iostream.h>
- #include <dos.h>
- #include <stdlib.h>
- #include <conio.h>
- void main()
- {
- randomize();
- if (!emsBlock::wInit())
- {
- cout << "sorry, your machine does not have EMS enabled.\n";
- return;
- }
- // emsData testData1;
- // testData1.pbAllocate(55);
- // testData1.pbAllocate(33);
- emsData *pDChunk1, *pDChunk2, *pDChunk3, *pDChunk4;
- pDChunk1 = new emsData;
- pDChunk2 = new emsData;
- pDChunk3 = new emsData;
- pDChunk4 = new emsData;
- cout << "\n\nEMSCheck-- short demo of EMS routines; press a key between sections.\n";
- cout << "First allocate three blocks of EMS memory.\n";
- getch();
- pDChunk1->pbAllocate(0);
- pDChunk2->pbAllocate(0);
- pDChunk3->pbAllocate(0);
- emsBlock::showBlockStatus();
- cout << "\n\nNow delete the second block:\n";
- getch();
- delete pDChunk2;
- emsBlock::showBlockStatus();
- cout << "\n\nNow we'll allocate a third block that fits between the two:\n";
- getch();
- pDChunk4->pbAllocate(5);
- emsBlock::showBlockStatus();
- cout << "\n\nAnd now we'll defragment the EMS to show it's compacted:\n";
- getch();
- emsBlock::defragmentAllEMS();
- emsBlock::showBlockStatus();
- cout << "\n\nAnd now an interesting test-- we'll allocate blocks of data\n";
- cout << "until there's no more room in EMS using random allocation:";
- getch();
- long sumOfMem = 0;
- emsData * pDNewData = NULL;
- // emsData testData;
- // testData.pbAllocate(55);
- emsBlock::showBlockStatus();
- getch();
- int iGo = 2;
- while(iGo)
- {
- pDNewData = new emsData;
- pDNewData->pbAllocate(random(32000) * 2);
- sumOfMem += pDNewData->wSize;
- cout << pDNewData->wSize << " \tbytes allocated with handle " << pDNewData->iHandle << "\n";
- if (pDNewData->iHandle == 0)
- --iGo;
- }
- emsBlock::showBlockStatus();
- cout << "Total memory allocated: " << sumOfMem << "\n";
- }
-
-
-